{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 1\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,\n",
    "> between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Consider use range(#begin, #end) method._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**\n",
    "\n",
    "- **Using for loops**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199,\b\n"
     ]
    }
   ],
   "source": [
    "for i in range(2000, 3201):\n",
    "    if i % 7 == 0 and i % 5 != 0:\n",
    "        print(i, end=\",\")\n",
    "print(\"\\b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "- **Using generators and list comprehension**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199\n"
     ]
    }
   ],
   "source": [
    "print(*(i for i in range(2000, 3201) if i % 7 == 0 and i % 5 != 0), sep=\",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 2\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program which can compute the factorial of a given numbers.The results should be printed in a comma-separated sequence on a single line.Suppose the following input is supplied to the program: 8\n",
    "> Then, the output should be:40320_**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **Using While Loop**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n",
      "362880\n"
     ]
    }
   ],
   "source": [
    "n = int(input())  # input() function takes input as string type\n",
    "# int() converts it to integer type\n",
    "fact = 1\n",
    "i = 1\n",
    "while i <= n:\n",
    "    fact = fact * i\n",
    "    i = i + 1\n",
    "print(fact)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **Using For Loop**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())  # input() function takes input as string type\n",
    "# int() converts it to integer type\n",
    "fact = 1\n",
    "for i in range(1, n + 1):\n",
    "    fact = fact * i\n",
    "print(fact)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **Using Lambda Function**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "5040\n"
     ]
    }
   ],
   "source": [
    "# Solution by:  harshraj22\n",
    "n = int(input())\n",
    "\n",
    "\n",
    "def shortFact(x):\n",
    "    return 1 if x <= 1 else x * shortFact(x - 1)\n",
    "\n",
    "\n",
    "print(shortFact(n))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 3\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_With a given integral number n, write a program to generate a dictionary that contains (i, i x i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.Suppose the following input is supplied to the program: 8_**\n",
    "\n",
    "> **_Then, the output should be:_**\n",
    "\n",
    "\n",
    "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n",
    "\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input.Consider use dict()_**\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **Using For loop**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "ans = {}\n",
    "for i in range(1, n + 1):\n",
    "    ans[i] = i * i\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **Using dictionary comprehension**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "ans = {i: i * i for i in range(1, n + 1)}\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
